﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Economo.Services.BusinessLogic;
using Economo.Services.BusinessEntities;

namespace DataLayerTestProject
{
    [TestClass]
    public class TestBanks
    {
        [TestMethod]
        public void TC_Banks_01_GetBanksByDescription()
        {
            BanksBusinessLogic bl = new BanksBusinessLogic();            
            List<Bank> banks =  bl.GetBanksByDescription("");
            Assert.AreEqual(banks.Count, 4);
            List<Bank> Santander = bl.GetBanksByDescription("Santander");
            Assert.AreEqual(Santander.Count, 1);
            List<Bank> santander = bl.GetBanksByDescription("santander");
            Assert.AreEqual(santander.Count, 1);
            List<Bank> nada = bl.GetBanksByDescription("nada");
            Assert.AreEqual(nada.Count, 0);
        }
        [TestMethod]
        public void TC_Banks_02_GetBankById()
        {
            BanksBusinessLogic bl = new BanksBusinessLogic();
            Bank santander = bl.GetBankById(1);
            Assert.AreEqual(santander.Description, "Santander");
            Bank nada = bl.GetBankById(150);
            Assert.IsNull(nada);
        }

        [TestMethod]
        public void TC_Banks_03_UpdateBanks()
        {
            BanksBusinessLogic bl = new BanksBusinessLogic();
            Bank toUpdate = new Bank();
            toUpdate.Id = 3;
            toUpdate.Description = "Itaú";
            bl.UpdateBank(toUpdate);
            Bank itau = bl.GetBankById(3);
            Assert.AreEqual(itau.Description, "Itaú");
            toUpdate.Description = "Itau";
            bl.UpdateBank(toUpdate);
        }

        [TestMethod]
        public void TC_Banks_04_InsertAndDeleteBanks()
        {
            BanksBusinessLogic bl = new BanksBusinessLogic();
            Int32 preInsert = bl.GetBanksByDescription("").Count;
            Bank newBank = new Bank();
            newBank.Description = "nuevo";
            byte newId = bl.InsertBank(newBank);
            Int32 postInsert = bl.GetBanksByDescription("").Count;
            Assert.AreEqual(preInsert+1, postInsert);
            bl.DeleteBank(newId);
            Int32 postDelete = bl.GetBanksByDescription("").Count;
            Assert.AreEqual(postInsert-1, postDelete);
            try
            {
                bl.DeleteBank(150);
                Assert.Fail("Wrong Delete didn`t throw an error message");
            }
            catch 
            {
                //This delete must fail
            }
        }


        [TestMethod]
        public void TC_Banks_05_EntityConversion()
        {
            BanksBusinessLogic bl = new BanksBusinessLogic();
            List<Bank> banks = bl.GetBanksByDescription("");
        }

    }
    
}
